package com.cskaoyan.controller.wechat;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.goods.Comment;
import com.cskaoyan.bean.goods.CommentExample;
import com.cskaoyan.mapper.CommentMapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author dengww
 * @create 2020/5/5 7:32
 */
@RestController
@RequestMapping("wx/comment")
public class WxCommentController {
    @Autowired
    CommentMapper commentMapper;

    @GetMapping("list")
    public BaseRespVo getCommentList() {
        CommentExample commentExample =new CommentExample();
        List<Comment> list = commentMapper.selectByExample(commentExample);
        return new BaseRespVo<>(0, list, "成功");
    }

    @PostMapping("count")
    public BaseRespVo replyComment() {
        CommentExample commentExample =new CommentExample();
        CommentExample.Criteria criteria = commentExample.createCriteria();
        List<Comment> comments = commentMapper.selectByExample(commentExample);
        long allcount = PageInfo.of(comments).getTotal();
        criteria.andHasPictureEqualTo(true);
        List<Comment> comments1=commentMapper.selectByExample(commentExample);
        long piccount = PageInfo.of(comments).getTotal();
        HashMap<String, Object> result = new HashMap<>();
        result.put("allCount", allcount);
        result.put("hasPicCount", piccount);
        return new BaseRespVo<>(0, result, "成功");
    }
}
